home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / DWSTKW / VB / VB4 / DWS.BAS
Encoding:
BASIC Source File  |  1996-07-08  |  17.9 KB  |  441 lines

  1. '******************************************************************************
  2. ' File:      dws.bas
  3. ' Version:   1.00
  4. ' Tab stops: every 2 columns
  5. ' Project:   DiamondWare's Sound ToolKit for Windows
  6. ' Copyright: 1994-1996 DiamondWare, Ltd.  All rights reserved.
  7. ' Written:   96/03/20 by David Allen
  8. ' Purpose:   Contains declarations for the DW Sound ToolKit for Windows
  9. ' History:   96/03/28 KW & JCL finalized for 1.0
  10. '            96/04/14 JCL finalized for 1.01
  11. '            96/05/13 JCL finalized for 1.1 (no changes)
  12. '            96/05/27 JCL finalized for 1.11 (no changes)
  13. '            96/07/08 JCL finalized for 1.2 (no changes)
  14. '
  15. '*Permission is expressly granted to use this program or any derivitive made
  16. ' from it to registered users of the WIN-STK.
  17. '******************************************************************************
  18.  
  19.  
  20.  
  21. Attribute VB_Name = "DWS"
  22. Option Explicit
  23.  
  24.  
  25. ' If a call to a dws_ function returns 0 (FALSE), then this is an
  26. ' indication that an error has occured.  Call dws_ErrNo to see which
  27. ' one.  The following series of Public Consts is the complete list of
  28. ' possible return values for dws_ErrNo.
  29. Public Const dws_EZERO = 0   ' no error
  30.  
  31. ' The following 8 errors may be triggered by any dws_ function
  32. Public Const dws_NOTINITTED = 1
  33. Public Const dws_ALREADYINITTED = 2
  34. Public Const dws_NOTSUPPORTED = 3
  35. Public Const dws_INTERNALERROR = 4
  36. Public Const dws_INVALIDPOINTER = 5
  37. Public Const dws_RESOURCEINUSE = 6
  38. Public Const dws_MEMORYALLOCFAILED = 7
  39. Public Const dws_SETEVENTFAILED = 8
  40.  
  41. ' dws_BUSY may be triggered during a call to a dws_ function, if any
  42. ' dws_ function is already executing.  Ordinarily, this should never
  43. ' occur.
  44. Public Const dws_BUSY = 9
  45.  
  46. ' This error may be triggered only by dws_Init 
  47. Public Const dws_Init_BUFTOOSMALL = 101
  48.  
  49. ' The following 3 errors may be triggered by any dws_D (dig) function
  50. Public Const dws_D_NOTADWD = 201
  51. Public Const dws_D_NOTSUPPORTEDVER = 202
  52. Public Const dws_D_BADDPLAY = 203
  53.  
  54. ' The following error may be triggered by dws_DPlay
  55. Public Const dws_DPlay_NOSPACEFORSOUND = 251
  56.  
  57. ' These 2 errors may be triggered by dws_WAV2DWD
  58. Public Const dws_WAV2DWD_NOTAWAVE = 301
  59. Public Const dws_WAV2DWD_UNSUPPORTEDFORMAT = 302
  60.  
  61. ' The following error may be triggered by any dws_M (music) function '
  62. Global Const dws_M_BADMPLAY = 401
  63.  
  64. '---------------------------------------------------------------------------
  65. ' This section Public Consts bitfields which are used by various dws_
  66. ' functions.  Each bit in a bitfield, by definition, may be set/reset
  67. ' independently of all other bits.
  68. '
  69.  
  70. ' flags for muscaps value of dws_DETECTRESULTS structure
  71. Public Const dws_muscap_NONE = &H0 ' no music playback
  72. Public Const dws_muscap_MIDIPORT = &H1 ' output port
  73. Public Const dws_muscap_SYNTH = &H2 ' generic int synth
  74. Public Const dws_muscap_SQSYNTH = &H4 ' square wave int synth
  75. Public Const dws_muscap_FMSYNTH = &H8 ' FM int synth
  76. Public Const dws_muscap_MAPPER = &H10 ' MIDI mapper
  77. Public Const dws_muscap_ANY = &H1F ' mask of all available modes
  78.  
  79. Public Const dws_digcap_NONE = &H0 ' no digitized sound playback
  80. Public Const dws_digcap_11025_08_1 = &H1 ' 11kHz, 8-bit, mono
  81. Public Const dws_digcap_11025_08_2 = &H2 ' 11kHz, 8-bit, stereo
  82. Public Const dws_digcap_11025_16_1 = &H4 ' 11kHz, 16-bit, mono
  83. Public Const dws_digcap_11025_16_2 = &H8 ' 11kHz, 16-bit, stereo
  84. Public Const dws_digcap_22050_08_1 = &H10 ' 22kHz, 8-bit, mono
  85. Public Const dws_digcap_22050_08_2 = &H20 ' 22kHz, 8-bit, stereo
  86. Public Const dws_digcap_22050_16_1 = &H40 ' 22kHz, 16-bit, mono
  87. Public Const dws_digcap_22050_16_2 = &H80 ' 22kHz, 16-bit, stereo
  88. Public Const dws_digcap_44100_08_1 = &H100 ' 44kHz, 8-bit, mono
  89. Public Const dws_digcap_44100_08_2 = &H200 ' 44kHz, 8-bit, stereo
  90. Public Const dws_digcap_44100_16_1 = &H400 ' 44kHz, 16-bit, mono
  91. Public Const dws_digcap_44100_16_2 = &H800 ' 44kHz, 16-bit, stereo
  92. Public Const dws_digcap_ANY = &HFFF ' mask of all available modes
  93.  
  94. ' The following Public Consts are bitfields used in the flags field in the
  95. ' dws_IDEAL struct.
  96. '
  97. ' SWAPLR should be used to compensate for downstream electronics which
  98. ' switch the left and right field.
  99. '
  100. ' Since pitch and volume change both require some additional CPU time,
  101. ' you may want to disable them for slow machines and enable for fast
  102. ' machines.  This is an easy way for you to do this, without changing
  103. ' your program around.
  104. '
  105. ' Notes:
  106. '   1) Pitch change is slower than volume change.
  107. '   2) Pitch decrease (dws_DPLAY.pitch > dws_IDENTITY) is slower than
  108. '      pitch increase
  109. '   3) When the source sound, or the STK, is 8-bit, raising the volume
  110. '      is slower than lowering it.  Otherwise both are equal.
  111. '
  112. Public Const dws_ideal_NONE = &H0            ' this is the normal case
  113. Public Const dws_ideal_SWAPLR = &H1          ' swap Left & Right on playback
  114. Public Const dws_ideal_DISABLEPITCH = &H2    ' disable the pitch feature
  115. Public Const dws_ideal_DISABLEVOLUME = &H4   ' disable the volume feature
  116. Public Const dws_ideal_MAXSPEED = &H6        ' use this for very slow machines
  117.  
  118. ' These are the flag bitfields for the dws_DPLAY structure.
  119. ' Each corresponds to one field in the struct.
  120.  
  121. Public Const dws_dplay_SND = &H1
  122. Public Const dws_dplay_COUNT = &H2
  123. Public Const dws_dplay_PRIORITY = &H4
  124. Public Const dws_dplay_PRESND = &H8
  125. Public Const dws_dplay_SOUNDNUM = &H10
  126. Public Const dws_dplay_LVOL = &H20
  127. Public Const dws_dplay_RVOL = &H40
  128. Public Const dws_dplay_PITCH = &H80
  129. Public Const dws_dplay_CALLBACK = &H100
  130. Public Const dws_dplay_SYNCHRONOUS = &h200
  131. Public Const dws_dplay_FIRSTSAMPLE = &h400
  132. Public Const dws_dplay_CURSAMPLE = &h800
  133. Public Const dws_dplay_LASTSAMPLE = &h1000
  134.  
  135. ' The following 2 consts indicate the status of music playback
  136. Public Const dws_MSONGSTATUSPLAYING = &H1
  137. Public Const dws_MSONGSTATUSPAUSED = &H2
  138.  
  139.  
  140. '---------------------------------------------------------------------------
  141. '
  142. ' When the WIN-STK sends a message to your window, the lParam field
  143. ' indicates the purpose of the message.
  144. '
  145. Public Const dws_event_SOUNDCOMPLETE = &H1
  146. Global Const dws_event_SOUNDSTARTED = &H2
  147. Global Const dws_event_SOUNDABORTED = &H3
  148.  
  149.  
  150. ' For no change in volume level or pitch
  151. Public Const dws_IDENTITY = &H100
  152.  
  153. ' Default priority, if not specified in call to dws_DPlay
  154. Public Const dws_NORMALPRIORITY = &H1000
  155.  
  156. '***************************************************************************
  157. 'This section declares the struct types used by the STK.  In each
  158. 'case, the user must create an instance of the struct prior to making
  159. 'a call to any STK function which takes a pointer to it.  The STK does
  160. 'not keep a pointer to any of these structs internally; after the call
  161. 'returns, you may deallocate it, if you wish.
  162. '
  163. 'NB: The STK _does_ keep pointers to digitized sound buffers!
  164. '
  165. 'A pointer to this struct is passed to dws_DetectHardWare, which fills
  166. 'it in.  It should then be passed to dws_Init.  If you plan on writing
  167. 'this struct out to a file, it's important that you write the entire
  168. 'contents.  There is information (for internal STK use only) in the
  169. 'reserved[] field!
  170.  
  171. Type dws_DETECTRESULTS
  172.     ' This field indicates which music capabilities are available, if any
  173.     muscaps As Long              ' see dws_muscap_xxxxxx Public Consts above
  174.  
  175.     ' This field indicates which dig capabilities are available, if any
  176.     digcaps As Long              ' see dws_digcaps_xxxxxx Public Consts above
  177.  
  178.     ' This field should be modified only with caution
  179.     digbfr As Long               ' size of buffer required by smallest capabilities
  180.  
  181.     reserved(20) As Byte
  182. End Type
  183.  
  184. ' A pointer to this struct is passed as a parameter to dws_Init.  This
  185. ' struct allows the program to let the STK know what capabilities it
  186. ' will actually use.
  187.  
  188. Type dws_IDEAL
  189.     flags As Long                ' use combination of dws_ideal_xxxx
  190.     mustyp As Long               ' use dws_muscap_xxxxxx
  191.  
  192.     digtyp As Long               ' use dws_digcaps_xxxxxx (mode) to select
  193.     dignvoices As Integer        ' maximum number of mixer channels to use (16 max)
  194.  
  195.     reserved(18) As Byte
  196. End Type
  197.  
  198. ' A pointer to this struct is passed to dws_DPlay.
  199. '
  200. ' Note that the soundnum field is filled in by dws_DPlay as a return value.
  201.  
  202. Type dws_DPlay
  203.     flags     As Long            ' flag word for active fields in struct
  204.     snd       As Long            ' pointer to buffer which holds a .DWD file
  205.     count     As Integer         ' number of times to play, or 0=infinite loop
  206.     priority  As Integer         ' higher numbers mean higher priority
  207.     presnd    As Integer         ' soundnum to sequence sound _after_
  208.     soundnum  As Integer         ' dws_DPlay returns a snd number from 10-65535
  209.     lvol      As Integer         ' 0-65535, 0 is off, 256 is dws_IDENTITY
  210.     rvol      As Integer         ' if the output is mono lvol & rvol are averaged
  211.     pitch     As Integer         ' 1-65535, 256 is dws_IDENTITY (0 is unuseable)
  212.     dummy     As Integer         ' added to insure DWORD alignment
  213.     
  214.     #If Win32 Then
  215.         hwndmsg As Long          ' handle of window to which to send msg
  216.         message As Long          ' message number to send to hwndmsg
  217.     #Else
  218.         hwndmsg As Integer       ' handle of window to which to send msg
  219.         message As Integer       ' message number to send to hwndmsg
  220.     #End If
  221.  
  222.     firstsample As Long          ' first sample of play buffer
  223.     cursample As Long            ' current sample of play buffer
  224.     lastsample As Long           ' last sample of play buffer
  225.  
  226.     #If Win32 Then
  227.         reserved(4) As Byte      ' 32 bit overhead
  228.     #Else
  229.         reserved(8) As Byte      ' 16 bit overhead
  230.     #End If
  231. End Type
  232.  
  233. ' A pointer to this struct is passed to dws_MPlay.
  234. Type dws_MPlay
  235.     track As String         ' pointer to buffer which holds a null terminated .MID file name
  236.     count As Integer        ' number of times to play, or 0=infinite loop
  237.  
  238.     reserved(10) As Byte
  239.  
  240. End Type
  241.  
  242. '***************************************************************************
  243.  
  244. #If Win32 Then
  245.     ' 32-bit Information/Types/Declarations
  246.  
  247.     ' This function is callable at any time.  It returns the number of the
  248.     ' last error which occured.
  249.  
  250.     Declare Function dws_ErrNo Lib "DWSW32.DLL" () As Integer
  251.      
  252.     ' Each function in this section has a boolean return value.    A 0 (false)
  253.     ' indicates that the function failed in some way.  In this case, call
  254.     ' dws_ErrNo to get the specific error.  Otherwise, a return value of 1
  255.     ' (true) indicates that all is well.
  256.     
  257.     Declare Function dws_DetectHardWare Lib "DWSW32.DLL" (dws_Type As dws_DETECTRESULTS) As Integer
  258.  
  259.     Declare Function dws_Init Lib "DWSW32.DLL" (dws_Type As dws_DETECTRESULTS, dws_ID As dws_IDEAL) As Integer
  260.     
  261.     ' If the program has called dws_Init, it _MUST_ call dws_Kill before it
  262.     ' terminates.
  263.  
  264.     Declare Function dws_Kill Lib "DWSW32.DLL" () As Integer
  265.  
  266.     ' The following function is the digital mixer of the STK.  A
  267.     ' value of 0 is off; dws_IDENTITY is normal, and 0xffff is maximum
  268.     ' volume (grossly distorted).
  269.  
  270.     Declare Function dws_XDig Lib "DWSW32.DLL" (ByVal lVolume As Integer, ByVal rVolume As Integer) As Integer
  271.     
  272.     ' The following 9 functions comprise the digitized sound functions of
  273.     ' the STK.  See the documentation for complete details.
  274.  
  275.     Declare Function dws_DPlay Lib "DWSW32.DLL" (dws_DP As dws_DPlay) As Integer
  276.  
  277.     ' Allows you to change the following items:
  278.     '   count
  279.     '   priority
  280.     '   lvol
  281.     '   rvol
  282.     '   pitch
  283.     '   hwndmsg and message (simultaneously)
  284.  
  285.     Declare Function dws_DSetInfo Lib "DWSW32.DLL" (dws_DP As dws_DPlay, dwsDP2 As Any) As Integer
  286.  
  287.     ' Can retrieve the current values for any or all of the following:
  288.     '   snd
  289.     '   count
  290.     '   priority
  291.     '   presnd
  292.     '   lvol
  293.     '   rvol
  294.     '   pitch
  295.     '   hwndmsg and message (simultaneously)
  296.  
  297.     Declare Function dws_DGetInfo Lib "DWSW32.DLL" (dws_DP As dws_DPlay, dwsDP2 As Any) As Integer
  298.     
  299.     ' Callable at any time--even before dws_Init or after dws_Kill
  300.     Declare Function dws_DGetRateFromDWD Lib "DWSW32.DLL" (snd As Long, Result As Integer) As Integer
  301.  
  302.     Declare Function dws_DDiscard Lib "DWSW32.DLL" (ByVal soundnum As Integer) As Integer
  303.  
  304.     Declare Function dws_DDiscardAO Lib "DWSW32.DLL" (snd As Long) As Integer
  305.  
  306.     Declare Function dws_DClear Lib "DWSW32.DLL" () As Integer
  307.  
  308.     Declare Function dws_DPause Lib "DWSW32.DLL" () As Integer
  309.  
  310.     Declare Function dws_DUnPause Lib "DWSW32.DLL" () As Integer
  311.  
  312.     ' Converts a .WAV buffer to a .DWD buffer
  313.     '
  314.     ' This function has two usages.  In the first, pass the wave pointer, the
  315.     ' wave length in *len and a NULL pointer for dwd.  The routine will return
  316.     ' the length of the buffer required to hold the resulting DWD in *len.  In
  317.     ' the second usage, allocate a buffer of the correct size and pass its
  318.     ' address in dwd.  Make sure you pass the wave pointer in wave and the size
  319.     ' of the wave in *len.  It will then perform the conversion, returning the
  320.     ' number of bytes used in *len.
  321.  
  322.     Declare Function dws_WAV2DWD Lib "DWSW32.DLL" (wave As Long, length As Long, snd As Long) As Integer
  323.  
  324.     ' The following 5 functions comprise the music functions of the STK. */
  325.     Declare Function dws_MPlay Lib "DWSW32.DLL" (dws_MP As dws_MPlay) As Integer
  326.  
  327.     Declare Function dws_MSongStatus Lib "DWSW32.DLL" (Result As Integer) As Integer
  328.  
  329.     Declare Function dws_MClear Lib "DWSW32.DLL" () As Integer
  330.  
  331.     Declare Function dws_MPause Lib "DWSW32.DLL" () As Integer
  332.  
  333.     Declare Function dws_MUnPause Lib "DWSW32.DLL" () As Integer
  334.     
  335.     ' If your 16-bit application can't yield CPU time to the system, it must
  336.     ' call this function periodically to prevent the sound from pausing.
  337.     ' This is not required for 32-bit applications, but the function is
  338.     ' supported for compatibility.
  339.  
  340.     Declare Function dws_Update Lib "DWSW32.DLL" () As Integer ' Affects all sounds
  341.  
  342. #ElseIf Win16 Then
  343.     ' 16-bit Information/Types/Declarations
  344.      
  345.     ' This function is callable at any time.  It returns the number of the
  346.     ' last error which occured.
  347.  
  348.     Declare Function dws_ErrNo Lib "DWSW16.DLL" () As Integer
  349.      
  350.     ' Each function in this section has a boolean return value.    A 0 (false)
  351.     ' indicates that the function failed in some way.  In this case, call
  352.     ' dws_ErrNo to get the specific error.  Otherwise, a return value of 1
  353.     ' (true) indicates that all is well.
  354.     
  355.     Declare Function dws_DetectHardWare Lib "DWSW16.DLL" (dws_Type As dws_DETECTRESULTS) As Integer
  356.  
  357.     Declare Function dws_Init Lib "DWSW16.DLL" (dws_Type As dws_DETECTRESULTS, dws_ID As dws_IDEAL) As Integer
  358.     
  359.     ' If the program has called dws_Init, it _MUST_ call dws_Kill before it
  360.     ' terminates.
  361.     
  362.     Declare Function dws_Kill Lib "DWSW16.DLL" () As Integer
  363.  
  364.     ' The following function is the digital mixer of the STK.  A
  365.     ' value of 0 is off; dws_IDENTITY is normal, and 0xffff is maximum
  366.     ' volume (grossly distorted).
  367.  
  368.     Declare Function dws_XDig Lib "DWSW16.DLL" (ByVal lVolume As Integer, ByVal rVolume As Integer) As Integer
  369.     
  370.     ' The following 9 functions comprise the digitized sound functions of
  371.     ' the STK.  See the documentation for complete details.
  372.  
  373.     Declare Function dws_DPlay Lib "DWSW16.DLL" (dws_DP As dws_DPlay) As Integer
  374.  
  375.     ' Allows you to change the following items:
  376.     '   count
  377.     '   priority
  378.     '   lvol
  379.     '   rvol
  380.     '   pitch
  381.     '   hwndmsg and message (simultaneously)
  382.  
  383.     Declare Function dws_DSetInfo Lib "DWSW16.DLL" (dws_DP As dws_DPlay, dwsDP2 As Any) As Integer
  384.  
  385.     ' Can retrieve the current values for any or all of the following:
  386.     '   snd
  387.     '   count
  388.     '   priority
  389.     '   presnd
  390.     '   lvol
  391.     '   rvol
  392.     '   pitch
  393.     '   hwndmsg and message (simultaneously)
  394.  
  395.     Declare Function dws_DGetInfo Lib "DWSW16.DLL" (dws_DP As dws_DPlay, dwsDP2 As Any) As Integer
  396.     
  397.     ' Callable at any time--even before dws_Init or after dws_Kill
  398.     Declare Function dws_DGetRateFromDWD Lib "DWSW16.DLL" (snd As Long, Result As Integer) As Integer
  399.  
  400.     Declare Function dws_DDiscard Lib "DWSW16.DLL" (ByVal soundnum As Integer) As Integer
  401.  
  402.     Declare Function dws_DDiscardAO Lib "DWSW16.DLL" (snd As Long) As Integer
  403.  
  404.     Declare Function dws_DClear Lib "DWSW16.DLL" () As Integer
  405.  
  406.     Declare Function dws_DPause Lib "DWSW16.DLL" () As Integer
  407.  
  408.     Declare Function dws_DUnPause Lib "DWSW16.DLL" () As Integer
  409.  
  410.     ' Converts a .WAV buffer to a .DWD buffer
  411.     '
  412.     ' This function has two usages.  In the first, pass the wave pointer, the
  413.     ' wave length in *len and a NULL pointer for dwd.  The routine will return
  414.     ' the length of the buffer required to hold the resulting DWD in *len.  In
  415.     ' the second usage, allocate a buffer of the correct size and pass its
  416.     ' address in dwd.  Make sure you pass the wave pointer in wave and the size
  417.     ' of the wave in *len.  It will then perform the conversion, returning the
  418.     ' number of bytes used in *len.
  419.  
  420.     Declare Function dws_WAV2DWD Lib "DWSW16.DLL" (wave As Long, length As Long, snd As Long) As Integer
  421.  
  422.     ' The following 5 functions comprise the music functions of the STK. */
  423.     Declare Function dws_MPlay Lib "DWSW16.DLL" (dws_MP As dws_MPlay) As Integer
  424.  
  425.     Declare Function dws_MSongStatus Lib "DWSW16.DLL" (Result As Integer) As Integer
  426.  
  427.     Declare Function dws_MClear Lib "DWSW16.DLL" () As Integer
  428.  
  429.     Declare Function dws_MPause Lib "DWSW16.DLL" () As Integer
  430.  
  431.     Declare Function dws_MUnPause Lib "DWSW16.DLL" () As Integer
  432.     
  433.     ' If your 16-bit application can't yield CPU time to the system, it must
  434.     ' call this function periodically to prevent the sound from pausing.
  435.     ' This is not required for 32-bit applications, but the function is
  436.     ' supported for compatibility.
  437.  
  438.     Declare Function dws_Update Lib "DWSW16.DLL" () As Integer ' Affects all sounds
  439.  
  440. #End If
  441.